#include <stdio.h>
#include <octopus.h>

#include "random.h"
#include "adc.h"
#include "test.h"
#include "eeprom.h"

struct octopus_context octopus;

int check_init()
{
  test_start("Init");

  if(octopus_init(&octopus) < 0)
  {
    test_failed("octopus_init");
    return -1;
  }

  if(octopus_open(&octopus) < 0)
  {
    test_failed("octopus_open");
    return -2;
  }

  test_ok();
  return 1;
}

int check_close()
{
  test_start("Close");

  if(octopus_close(&octopus) < 0)
  {
    test_failed("octopus_close");
    return -1;
  }

  test_ok();
  return 1;
}

int main(void)
{
  int ok, total;

  check_init();
  check_eeprom();
  check_adc();
  check_close();

  test_stats(&ok, &total);

  printf("-----------------------------\n");
  printf("| passed: %d/%d (%.2f%%)      |\n", ok, total, (double)ok/total*100);
  printf("-----------------------------\n");

  if(ok == total)
    return 0;
  else
    return 1;
}
